1
超越單一提示:向複雜工作流程的轉變
AI010Lesson 4
00:00

「巨量提示」的終結

在早期大語言模型(LLM)開發中,使用者經常試圖將每一個指令、限制條件和資料點都塞進單一且龐大的提示中。雖然直覺上合理,但這種做法會導致過度擬合,高額的令牌成本,並形成一個「黑箱」,使調試錯誤幾乎變得不可能。

業界正逐步轉向提示串接。這種模組化方法將大語言模型視為一系列專門的工作者,而非一位過度負荷的通才。

為什麼要串接提示?

  • 可靠性:將複雜任務分解為可管理的子任務,能大幅降低幻覺發生率。
  • 整合性:它允許你在工作流程中途動態注入來自外部工具(如內部 JSON 資料庫或 API)的資料。
  • 成本效益:你只需傳送每個特定步驟所需的必要上下文,節省令牌消耗。
慣例原則:任務分解
單一提示應僅負責一個特定的工作。如果你發現自己在單一提示指令中使用了超過三個「然後」語句,就該將它們串接成獨立的呼叫了。
pipeline.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute pipeline.
>
Knowledge Check
Why is "Dynamic Context Loading" (fetching data mid-workflow) preferred over putting all possible information into a single system prompt?
It makes the model run faster on local hardware.
It prevents model confusion and reduces token costs by only providing necessary data.
It allows the model to ignore the system instructions.
Challenge: Designing a Safe Support Bot
Apply prompt chaining principles to a real-world scenario.
You are building a tech support bot. A user asks for the manual of a "X-2000 Laptop."

Your task is to define the logical sequence of prompts needed to verify the product exists in your database and ensure the final output doesn't contain prohibited safety violations.
Step 1
What should the first two actions in your pipeline be immediately after receiving the user's message?
Solution:
1. Input Moderation: Check if the prompt contains malicious injection attempts. Evaluate as $ (N/Y) $.
2. Entity Extraction: Use a specialized prompt to extract the product name ("X-2000 Laptop") from the raw text.
Step 2
Once the entity is extracted, how do you generate the final safe response?
Solution:
1. Database Lookup: Query the internal DB for "X-2000 Laptop" manual data.
2. Response Generation: Pass the user query AND the retrieved DB data to the LLM to draft an answer.
3. Output Moderation: Run a final check on the generated text to ensure no safety policies were violated before sending it to the user.